#include "analysis_base.h"
#include <QObject>
#include <QApplication>
#include <QInputDialog>

AnalysisBase::AnalysisBase( DataSet *theData ) {
    _theData = theData;
    _results = new ResultsDocument();
}

bool AnalysisBase::selectPartition(){
    QStringList strata = _theData->getStrataKeys();
    QString selectedStratum;

    if( strata.count() == 1 )
        selectedStratum = strata[0];
    else {
        bool ok;
        selectedStratum = QInputDialog::getItem( qApp->activeWindow(),
                                                 QObject::tr("Which Stratum?"),
                                                 QObject::tr("Select Partition"),
                                                 strata,0,false,&ok);
        if( !ok ) return false;
    }

    partitionOn( selectedStratum );
    return true;
}

void AnalysisBase::partitionOn(QString strataName){
    _theData->partitionByStratum( strataName );
}

void AnalysisBase::dumpHeader(QString name) {
    _results->appendHeader(QString("%1 Results").arg(name));
    QStringList info;
    info << QString("Individuals: %1").arg(_theData->numInds());
    info << QString("Populations: %1").arg(_theData->numPops());
    _results->appendList(info,false);

}

